<template>
  <el-card>
    <el-tabs v-model="activeName">
      <el-tab-pane label="登录账户设置" name="loginInfo">
        <el-form
          label-width="80px"
          style="width: 350px; margin: 50px auto"
          :model="userInfo"
          :rules="rules"
          ref="form"
        >
          <el-form-item label="姓名：" prop="username">
            <el-input v-model="userInfo.username"></el-input>
          </el-form-item>
          <el-form-item label="密码：" prop="password">
            <el-input type="password" v-model="userInfo.password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="update()">更新</el-button>
            <el-button @click="$router.back()">取消</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="个人详情" name="userInfo">
        <user-info></user-info>
      </el-tab-pane>
      <el-tab-pane label="岗位信息" name="jobInfo">
        <job-info></job-info>
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import { userProfile, saveProfile } from "@/api/user";
import UserInfo from "./component/user-info.vue";
import JobInfo from "./component/job-info.vue";
export default {
  name: "detail",
  components: {
    UserInfo,
    JobInfo,
  },
  created() {
    this.getBaseProfile();
  },
  data() {
    return {
      activeName: "loginInfo",
      userInfo: {},
      rules: {
        username: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur",
          },
          {
            min: 1,
            max: 5,
            message: "姓名只能在1-5个字符",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    async getBaseProfile() {
      let res = await userProfile(this.$route.query.id);
      this.userInfo = res.data;
    },
    update() {
      this.refs.form.validate(async (v) => {
        if (v) {
          await saveProfile(this.form);
          this.$message.success("更新成功");
        }
      });
    },
  },
};
</script>

<style>
</style>